package org.xsk.mall.pms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.xsk.mall.api.pms.*;
import org.xsk.mall.api.pms.product.ProductCategoryService;
import org.xsk.mall.pms.controller.convert.ProductCategoryConvert;
import org.xsk.mall.pms.domain.model.PmsProductCategoryModel;
import org.xsk.mall.pms.domain.model.PmsProductCategoryQueryModel;
import org.xsk.mall.pms.service.ProductCategoryApplicationService;

import java.util.List;

/**
 * description: 商品分类管理
 * <p>
 * date: 2021/7/9 10:35
 * author: x-one
 */
@RestController
@Api(value = "ProductCategoryController")
public class ProductCategoryController implements ProductCategoryService {

    @Autowired
    private ProductCategoryApplicationService applicationService;

    @Override
    @ApiOperation(value = "分页查询产品分类列表")
    public PageQueryCategoryResp pageQueryCategory(
            @ApiParam("PageQueryCategoryReq") PageQueryCategoryReq pageQueryCategoryReq) {
        PmsProductCategoryQueryModel queryModel = ProductCategoryConvert.INSTANCE.reqToModel(pageQueryCategoryReq);
        Page<PmsProductCategoryModel> modelPage = applicationService.pageQueryCategory(queryModel);
        List<PageQueryCategoryRespData> dataList =
                ProductCategoryConvert.INSTANCE.modelListToDataList(modelPage.getRecords());

        return PageQueryCategoryResp.newBuilder().addAllData(dataList).build();
    }

    @Override
    @ApiOperation(value = "新增产品分类")
    public SaveProductCategoryResp saveProductCategory(
            @ApiParam("SaveProductCategoryReq") SaveProductCategoryReq saveProductCategoryReq) {
        applicationService.saveProductCategory();
        return SaveProductCategoryResp.newBuilder().build();
    }
}